<?php

namespace app\api\controller\xyvenue;
use app\common\controller\Api;
use app\api\model\xyvenue\Venue as VenueModel;

/**
 * 场地接口
 */
class Venue extends Api
{
    protected $noNeedLogin = ['init'];
    protected $noNeedRight = ['*'];
    
	/**
     * 加载预定数据
     */
    public function init()
    {
        $params = $this->request->get();
        $detail = VenueModel::getInit($params);
        $this->success('加载预定数据', $detail);
    }
    
    public function Addvenue(){
        
         // 获取请求数据
        $data =  $this->request->post();
        
        // 进行数据验证
        $validate = new \think\Validate([
            'facevalue' => 'require',
            'buyprice'  => 'require',
            'remark'    => 'require',
            // 'status'   => 'require',
        ]);
        
        if (!$validate->check($data)) {
            // return json(['code' => 0, 'msg' => $validate->getError()]);
        }
        
        // 模型实例化
        $model = new VenueModel();
        
        // $data['status'] =  'normal';
        
        // print_r($data);
        // exit();
        
        $data['area'] = json_encode($data['area'],JSON_UNESCAPED_UNICODE);
        $data['timeprice'] = json_encode($data['timeprice'],JSON_UNESCAPED_UNICODE);
        
        // 数据保存
        if ($model->allowField(true)->save($data)) {
            
            return $this->success('保存成功');
            
        } else {
            return $this->success('保存失败');
        }
    }

}